package com.spring.sunflower.userinfo;

import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.CommonBean;
import com.spring.sunflower.bean.PhotoListBean;
import com.spring.sunflower.bean.PhotoListReleaseBean;
import com.spring.sunflower.bean.STSCertBean;
import com.spring.sunflower.common.CommonContract;

import java.util.Map;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/7/2<br/>
 * <p>
 * Describe:<br/>
 */
public class PhotoWallPresenter extends BasePresenter<CommonContract.PhotoWallView> {

    public PhotoWallPresenter(CommonContract.PhotoWallView baseView) {
        super(baseView);
    }

    public void releasePhoto(Map<String, String> map) {
        Observable<PhotoListReleaseBean> observable = requestDataSource.releasePhoto(map);
        addDisposable(observable, new BaseObserver<PhotoListReleaseBean>(baseView) {

            @Override
            public void onSuccess(PhotoListReleaseBean bean) {
                baseView.updateSuccess(bean.getDatas());
            }

            @Override
            public void onError(int status, String msg) {
                baseView.updateFailed();
            }
        });
    }

    public void queryPhoto(Map<String, String> map) {
        Observable<PhotoListBean> observable = requestDataSource.queryPhoto(map);
        addDisposable(observable, new BaseObserver<PhotoListBean>(baseView) {

            @Override
            public void onSuccess(PhotoListBean bean) {
                baseView.querySuccess(bean.getDatas());
            }

            @Override
            public void onError(int status, String msg) {
                baseView.queryFailed();
            }
        });
    }

    public void deletePhoto(Map<String, String> map,int position) {
        Observable<CommonBean> observable = requestDataSource.deletePhoto(map);
        addDisposable(observable, new BaseObserver<CommonBean>(baseView) {

            @Override
            public void onSuccess(CommonBean bean) {
                baseView.deleteSuccess(position);
            }

            @Override
            public void onError(int status, String msg) {
                baseView.deleteFailed();
            }
        });
    }
    public void getSTSCert() {
        Observable<STSCertBean> observable = requestDataSource.getSTSCert();
        addDisposable(observable, new BaseObserver<STSCertBean>(baseView) {

            @Override
            public void onSuccess(STSCertBean bean) {
                STSCertBean.DatasBean datas = bean.getDatas();
                baseView.loadSTSCert(datas);
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
}}
